/*
 *  * Copyright  rocedu@BESTI   rocedu@qq.com   All rights reserved.
 *   *
 *    * 鏂囦欢鍒涘缓绋嬪簭锛屾帴鍙椾竴涓懡浠よ鍙傛暟浣滀负鏂囦欢鍚嶅苟鍒涘缓璇ユ枃浠躲€?
 *     * 濡傛灉鍙傛暟涓嶆纭垨鏂囦欢鍒涘缓澶辫触锛岀▼搴忓皢鎵撳嵃閿欒淇℃伅銆?
 *      */

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <linux/limits.h>

int main(int argc, char *argv[]) {
	    int errornum;  // 鍙橀噺鐢ㄤ簬瀛樺偍閿欒浠ｇ爜
	        char filename[PATH_MAX] = {0};  // 鐢ㄤ簬瀛樺偍鏂囦欢鍚嶇殑瀛楃鏁扮粍锛屽垵濮嬪寲涓?

		    // 妫€鏌ュ懡浠よ鍙傛暟鏁伴噺鏄惁姝ｇ‘
		         if (argc != 2) {
		                 fprintf(stderr, "You must supply a filename as an argument \n");
		                         return 1;  // 杩斿洖1琛ㄧず閿欒
		                             }
		    
		                                 // 瀹夊叏鍦版嫹璐濆懡浠よ鎻愪緵鐨勬枃浠跺悕鍒癴ilename鏁扮粍
		                                     strncpy(filename, argv[1], sizeof(filename) - 1);
		                                         // 纭繚鏈€鍚庝竴涓瓧绗︿负'\0'浠ラ伩鍏嶅瓧绗︿覆鏈粓姝?
		                                             filename[sizeof(filename) - 1] = '\0';
		    
		                                                 // 鍒涘缓鏂囦欢骞惰缃潈闄愪负0644
		                                                     if (creat(filename, 00644) == -1) {
		                                                             errornum = errno;  // 淇濆瓨errno鐨勫€?
		                                                                     fprintf(stderr, "Can't create file %s \n", filename);  // 鎵撳嵃鏂囦欢鍒涘缓閿欒淇℃伅
		                                                                             fprintf(stderr, "%s \n", strerror(errornum));  // 鎵撳嵃鍏蜂綋鐨勯敊璇師鍥?
		                                                                                     return 1;  // 杩斿洖1琛ㄧず閿欒
		                                                                                         }
		    
		                                                                                             return 0;  // 杩斿洖0琛ㄧず鎴愬姛
		                                                                                             }
		    
